<template>
  <div class="company-wrap">
    <div class="company-box">

      <div class="company-con" v-for="(item,index) in itemList" :key="index">
        <van-radio-group v-model="company" class="company-radio">
          <van-radio :name="item.id" class="company" checked-color="#FF8F33"
                     @click="chooseValue(item.id,item.mechanismName)">{{item.mechanismName}}
          </van-radio>
        </van-radio-group>
        <img src="../../../images/edit.png" class="pic1" @click="editBrief(item.id)"/>
      </div>

      <div class="add-box" @click="briefPage">
        <img src="./add.png" class="pic2"/>
        <span class="add-title">添加新企业</span>
      </div>

    </div>
  </div>

</template>

<script>
  import {queryMechanismList} from '../../../axios/api'

  export default {
    data() {
      return {
        company: "",
        itemList: [],
        type: this.$route.query.type,
        workId: this.$route.query.workId,
        mechanismId: this.$route.query.mechanismId
      }
    },
    mounted() {
      this.identity = this.$store.getters.getIdentity;
      this.queryList();
    },
    methods: {
      queryList() {
        this.$vux.loading.show({
          text: '加载中',
        });
        const params = {
          "sgin": this.identity
        };

        queryMechanismList(params).then(res => {
          this.$vux.loading.hide();
          console.log(JSON.stringify(res.data[0]))
          if (res.code == 0 && res.data != null) {
            this.itemList = res.data;
            for (let i = 0; i < this.itemList.length; i++) {
              if (this.mechanismId == this.itemList[i].id) {
                this.company = this.itemList[i].id;
              }
            }
          }
        });
      },
      briefPage() {//简介页
        if (this.type == 1) {
          this.$router.push({path: "/workbreif", query: {"type": this.type, "mark": 1}});
        } else {
          this.$router.push({
            path: "/workbreif",
            query: {"type": this.type, "mark": 1, "mechanismId": this.mechanismId, "workId": this.workId, "flag": 1}
          });
        }
      },
      editBrief(id) {
        this.$router.push({
          path: "/workbreif",
          query: {"type": this.type, "mark": 2, "mechanismId": id, "workId": this.workId, "flag": 1}
        });
      },
      chooseValue(id, name) {
        setTimeout(() => {
          if (this.type == 1) {
            this.$router.push({path: "/workedit", query: {"mechanismId": id, "mechanismName": name, "type": 1}});
          } else {
            this.$router.push({
              path: "/workedit",
              query: {
                "mechanismName": name,
                "mechanismId": id,
                "workId": this.workId,
                "type": 2,
                "flag": 1
              }
            });
          }
        }, 200)
      }
    }
  }
</script>

<style lang="less" scoped>
  @import "../../../assest/mixin";

  .company-wrap {
    .wh(100%, 100%);
    background: @talent-theme-bg-color;
    .company-box {
      .wh(100%, auto);
      background: @talent-bg-color;
      .company-con {
        display: flex;
        align-items: center;
        margin-left: 3.2%;
        .wh(96.8%, 1.333rem);
        border-bottom: @talent-border-bottom;
        .company-radio {
          .company {
            display: flex;
            align-items: center;
            .size-color(0.427rem, rgba(51, 51, 51, 1));
          }

          .company /deep/ .van-radio__icon {
            .wh(0.4rem, 0.4rem);
            line-height: 0.4rem;
          }
          .company /deep/ .van-radio__icon .van-icon {
            .wh(0.4rem, 0.4rem);
            border-radius: 0.107rem;
            border: 1px solid #e5e5e5;
            background: #E5E5E5;
          }
        }
        .pic1 {
          margin-left: auto;
          margin-right: 0.32rem;
          .wh(0.48rem, 0.48rem)
        }
      }
      .add-box {
        .fj(center, center);
        .wh(100%, 1.333rem);
        .add-title {
          padding-left: 0.133rem;

          .size-color(0.427rem, rgba(255, 143, 51, 1));
        }
        .pic2 {
          padding-right: 0.133rem;
          .wh(0.48rem, 0.48rem)
        }
      }
    }
  }

</style>
